package com.school.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.school.mapper.FileMapper;
import com.school.mapper.TeacherMapper;
import com.school.pojo.File;
import com.school.pojo.Student;
import com.school.pojo.Teacher;
import com.school.service.TeacherService;

@Service
@Transactional
public class TeacherServiceImpl implements TeacherService{

	@Autowired
	private TeacherMapper teacherMapper;
	
	@Autowired
	private FileMapper fileMapper;
	
	@Override
	public List<Teacher> findAll(int page, int pageSize, Teacher t) {
		PageHelper.startPage(page,pageSize);
		
		return teacherMapper.findAll(t);
	}

	@Override
	public int add(Teacher teacher) {
		return teacherMapper.add(teacher);
	}

	@Override
	public Teacher findbyId(int teacher_id) {
		
		return teacherMapper.findbyId(teacher_id);
	}

	@Override
	public int edit(Teacher t) {
		return teacherMapper.edit(t);
	}

	@Override
	public int delbatch(int[] id) {
		// TODO Auto-generated method stub
		return teacherMapper.delbatch(id);
	}

	@Override
	public Teacher findByAId(Integer account_id) {
	
		Teacher Teacher2=new  Teacher();
		
		Teacher teacher=teacherMapper.findByAId(account_id);
		if(teacher!=null) {
		File file= fileMapper.findbyId(teacher.getFile_id());
		
		Teacher2.setName(teacher.getName());
		Teacher2.setUrl(file.getUrl());
		}
		
		return Teacher2;
	}

}
